<template>
	<view class="content wid100">
		<scroll-view :style="'height: '+btom+';'" class="wid100" :scroll-y="!panduan && !dhm && !gonggao && !tianjiazuomian" @scrolltolower="lower">
			<view class="poRel wid90 mar" style="z-index: 1;">
				<view class="poFix wid90 dis disAl disJuB hei86 bacFFF" style="top: 0;z-index: 2;">
					<view class="foSi25 borRad40" @click="fuankui()"
						style="color: #ff5987;border: 1rpx solid #ff5987;padding: 10rpx 30rpx;">反馈</view>
					<view class="dis disAl borRad40 hei60" style="width: 400rpx;background-color: #EEEEEE;">
						<view class="dis disJuC" style="width: 13%;">
							<uni-icons type="search" size="30rpx" color="#AFB6B1"></uni-icons>
						</view>
						<input class="wid85 foSi25" v-model="sousuo" @input="sousuoInput" 
							placeholder="请输入搜索内容" placeholder-style="color: #AFB6B1;"/>
					</view>
					<view class="foSi25 borRad40" @click="jinqun()"
						style="color: #ff5987;border: 1rpx solid #ff5987;padding: 10rpx 30rpx;">进群</view>
				</view>
				<view class="dis disAl disJuC hei86"></view>
				<swiper v-if="bannerList.length > 0" class="wid100 mar borRad20" style="height: 430rpx;" circular :autoplay='true'>
					<swiper-item v-for="(item,index) in bannerList" :key="index">
						<image :src="item.banner_img" @click="tiaozhuan(item.link_url)"
							class="wh100 borRad20" mode="scaleToFill"></image>
					</swiper-item>
				</swiper>
				<view v-if="noticeList.length > 0" class="wid100 mar-top20 hei86 dis disAl disJuC" style="background-color: #FFF9EA;color: #FF9A43;">
					<uni-icons type="sound" color="#FF9A43" size="40rpx" />
					<swiper class="wid80 borRad20 hei100 mar-left20" circular :autoplay='true' :vertical='true'>
						<swiper-item class="hei100" v-for="(item,index) in noticeList" :key="index">
							<view class="wh100 dis disAl" @click="gonggaoClick(item)">
								<view class="wid100 webkitLineClamp foSi30 liH40">{{item.title}}</view>
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>
			<view class="poRel wid95 mar borRad20 mar-top30" 
				style="z-index: 1;box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
				<view class="hei20"></view>
				<view v-if="xuanList.length > 0" class="wid95 mar dis flwa">
					<block v-for="(item,index) in xuanList" :key="index">
						<view class="borRad40 dis disAl disJuC foSi25 hei60 mar-bott20 coFFF" 
						style="width: 24%;box-sizing: border-box;background-size: 100% 100%;"
						:style="'background-image: url('+(xuan == index? url+'/wechat/cho.jpg': url+'/wechat/ch.jpg')+');'+
						((index+1) % 4 != 0?'margin-right: 1.333%':'')" @click="xuanClick(index)">{{item.name}}</view>
					</block>
				</view>
			</view>
			<view class="poRel wid90 mar" style="z-index: 1;">
				<block v-for="(item,index) in list" :key="index">
					<view class="wid100 dis" style="padding: 40rpx 0;">
						<view class="wid20" style="height: 110rpx;">
							<image :src="item.cover_img" class="hei100 borRad20" style="width: 110rpx;"></image>
						</view>
						<view class="wid80 dis disJuB">
							<view class="wid70">
								<view class="foSi30 liH40">{{item.name}}</view>
								<view class="foSi30 mar-top10 liH40">{{item.sub_name}}</view>
								<view class="foSi22 mar-top10 wid100 webkitLineClamp" 
									style="color: #888;">{{item.brief}}</view>
							</view>
							<view class="dis disAl">
								<view class="foSi25 borRad40" @click="huoqu(index)"
									style="color: #ff5987;border: 1rpx solid #ff5987;padding: 10rpx 30rpx;">获取</view>
							</view>
						</view>
					</view>
					<view v-if="index +1 != list.length" class="wid100" style="height: 1rpx;background-color: #ccc;"></view>
				</block>
			</view>
		</scroll-view>
		<view v-if="gonggao" class="wid100 poAbs zhezhao" :style="'height: '+btom+';'">
			<view class="wh100 poRel dis disAl disJuC" style="z-index: 10;">
				<view style="width: 650rpx;">
					<scroll-view class="wid100 bacFFF borRad20" style="height: 700rpx;padding: 30rpx 0;" scroll-y="true">
						<view class="wid90 mar">
							<rich-text :nodes="gonggaoText"></rich-text>
						</view>
					</scroll-view>
					<view class="mar-top30 dis disAl disJuC">
						<uni-icons type="close" color="#fff" size="45rpx" @click="gonggao = false"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view v-if="tianjiazuomian" class="wid100 poAbs zhezhao1" @click="guanbi" :style="'height: '+btom+';'">
			<view class="wh100 poRel dis disJuC" style="z-index: 10;align-items: flex-end;">
				<view class="wid90">
					<image v-if="system == 'ios'" src="../../../static/ios_z1.png" class="wid100" mode="widthFix"></image>
					<image v-if="system == 'Android'" src="../../../static/android_z1.png" class="wid100" mode="widthFix"></image>
					<view style="height: 40rpx;"></view>
				</view>
			</view>
		</view>
		<view v-if="panduan" class="wid100 poAbs zhezhao1" :style="'height: '+btom+';'">
			<view class="wh100 poRel" style="z-index: 10;">
				<view class="wid90 mar">
					<view style="height: 40rpx;"></view>
					<image v-if="system == 'ios'" src="../../../static/ios_z.png" class="wid100" mode="widthFix"></image>
					<image v-if="system == 'Android'" src="../../../static/android_z.png" class="wid100" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<view v-if="dhm" class="wid100 poAbs zhezhao" :style="'height: '+btom+';'">
			<view class="wh100 dis disAl disJuC poRel" style="z-index: 10;">
				<view style="width: 650rpx;">
					<scroll-view class="wid100 bacFFF borRad20" style="height: 700rpx;padding: 30rpx 0;" scroll-y="true">
						<view class="dis disJuC" style="height: 200rpx;">
							<!-- <image src="../../../static/logo.png" class="hei100" style="width: 200rpx;"></image> -->
							<image :src="image" class="hei100" style="width: 200rpx;"></image>
						</view>
						<view class="borRad40 dis disAl disJuC hei86 wid90 mar mar-top30" style="background-color: #EEEEEE;">
							<input class="wid90 textCen" v-model="code" placeholder="请输入兑换码"/>
						</view>
						<view class="wid90 mar dis disAl mar-top40" style="justify-content: space-around;">
							<button class="dis disAl disJuC hei60 borRad40 coFFF foSi28" @click="zhantie()"
								style="width: 280rpx;background-color: #00AD27;">粘贴并打开</button>
							<view class="dis disAl disJuC hei60 borRad40 coFFF foSi28" @click="duihuan()"
								style="width: 280rpx;background-color: #00AD27;">兑换</view>
						</view>
						<view class="wid90 mar">
							<view style="height: 40rpx;"></view>
							<rich-text :nodes="dhmData"></rich-text>
						</view>
					</scroll-view>
					<view class="mar-top30 dis disAl disJuC">
						<uni-icons type="close" color="#fff" size="45rpx" @click="dhm = false"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				gonggao: false,
				timer: null,
				sousuo: '',
				panduan: false,
				tianjiazuomian: false,
				xuan: 0,
				xuanList: [],
				biaoshi: null,
				dhm: false,
				code: null,
				dhmData: '',
				last_page: 0,
				page: 1,
				list: [],
				gonggaoList: [],
				gonggaoText: '',
				kefu: '',
				bannerList: [],
				noticeList: [],
				name: '',
				image1: '',
				image: '',
				need_codes: '',
				wechat_qun: '',
				qun_link: '',
				btom: 0,
				system: 'Android',
			}
		},
		mounted() {
			this.btom = uni.getWindowInfo().windowHeight+"px"
			console.log(this.btom);
		},
		onLoad() {
			if (uni.getSystemInfoSync().platform == 'ios') {
				this.system = 'ios'
			}
			this.panduan = false
			if(!uni.getStorageSync('yindao')){
				uni.setStorageSync('yindao', 1);
				this.tianjiazuomian = true
			}
			this.getNeirong()
			this.getPeizhi()
			// let status = navigator.userAgent.toLowerCase();
			// if (status.match(/MicroMessenger/i) == "micromessenger") { // 是微信浏览器 
			// 	console.log("是微信浏览器");
			// 	this.gonggao = false
			// 	this.panduan = true
			// } else { // 不是微信浏览器 
			// 	console.log("不是微信浏览器");
			// 	this.panduan = false
			// 	if(!uni.getStorageSync('yindao')){
			// 		uni.setStorageSync('yindao', 1);
			// 		this.tianjiazuomian = true
			// 	}
			// 	this.getNeirong()
			// 	this.getPeizhi()
			// }
		},
		methods: {
			guanbi(){
				var that = this
				that.tianjiazuomian = false
				var time = uni.getStorageSync('gonggao')?Number(uni.getStorageSync('gonggao'))+1000*60*10:0
				var time1 = new Date().getTime()
				if(!time || time <= time1) {
					uni.setStorageSync('gonggao', time1);
					that.gonggao = true
				}
			},
			gonggaoClick(item){
				uni.navigateTo({
					url: '/pages/common/richtext?id='+item.id+'&type=1'
				})
			},
			tiaozhuan(href){
				if(href){
					window.location.href = href
				}
			},
			jinqun(){
				window.location.href = this.qun_link
			},
			fuankui(){
				uni.navigateTo({
					url: '/pages/common/richtext?type=3'
				})
			},
			zhantie(){
				var that = this
				navigator.clipboard.readText().then((text) => {
					console.log('获取到的文本内容是：', text)
					that.code = text
					that.duihuan()
				}).catch((err) => {
					console.error('读取剪贴板内容失败：', err)
				});
				// 获取系统剪贴板内容
				// uni.getClipboardData({
				// 	success: (res) => {
				// 		console.log(res.data)
				// 		// const text = res.data;
				// 		that.code = res.data
				// 		that.duihuan()
				// 	},
				// 	fail(res) {
				// 		console.log(res)
				// 	}
				// });
			},
			duihuan(){
				var that = this;
				if(!that.code){return uni.showToast({title: '请输入兑换码',icon: 'error',duration: 2000})};
				uni.setStorageSync('dhm',that.code)
				uni.setStorageSync('get_type_dhm',1)
				uni.request({
					url: that.global.url + 'api/zy/use_codes',
					method: "POST",
					header: {},
					data: {
						codes: that.code
					},
					success(res) {
						let result = res.data
						that.dhm = false
						that.code = ''
						if (result.code == 1) {
							// var idList = uni.getStorageSync('idList')?uni.getStorageSync('idList'):[]
							// idList = idList.concat(that.list[that.biaoshi].id)
							// uni.setStorageSync('idList',idList)
							if(that.list[that.biaoshi].type == 3){
								uni.navigateTo({
									url: '/pages/common/download?id='+that.list[that.biaoshi].id+'&name='+that.name+'&image='+that.image1
								})
							}else if(that.list[that.biaoshi].type == 1){
								uni.navigateTo({
									url: '/pages/common/richtext?id='+that.list[that.biaoshi].id+'&type=2'
								})
							}else if(that.list[that.biaoshi].type == 2){
								uni.navigateTo({
									url: '/pages/common/account?id='+that.list[that.biaoshi].id
								})
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			getPeizhi(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/zy/get_popup',
					method: "POST",
					header: {},
					data: {},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.need_codes = result.data.need_codes
							that.wechat_qun = result.data.wechat_qun
							that.qun_link = result.data.qun_link
							var gonggaoText = result.data.index_tips
							gonggaoText = gonggaoText.replace(/<img/gi, "<img class='richImg'");
							that.gonggaoText = gonggaoText
							that.name = result.data.gzh_name
							uni.setNavigationBarTitle({
								title: result.data.gzh_name
							});
							that.image1 = result.data.gzh_icons
							var data = result.data.gzh_content
							data = data.replace(/<img/gi, "<img class='richImg'");
							that.dhmData = data
							that.image = result.data.gzh_img
							if(!that.tianjiazuomian){
								var time = uni.getStorageSync('gonggao')?Number(uni.getStorageSync('gonggao'))+1000*60*10:0
								var time1 = new Date().getTime()
								if(!time || time <= time1) {
									uni.setStorageSync('gonggao', time1);
									that.gonggao = true
								}
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			getNeirong(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/zy/index_data',
					method: "POST",
					header: {},
					data: {},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.bannerList = result.data.banner
							that.noticeList = result.data.notice
							that.xuanList = result.data.fica
							that.page = 1
							that.getList()
							// for(var i=0; i<that.xuanList.length; i++){
							// 	if(that.xuanList[i].type == 1){
							// 		that.xuan = i
							// 		that.page = 1
							// 		that.getList()
							// 		return
							// 	}
							// }
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			sousuoInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.sousuo = event.target.value
					that.page = 1
					that.getList()
					console.log(that.sousuo)
				}, 1000)
			},
			getList(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/zy/article_list',
					method: "POST",
					header: {},
					data: {
						page: that.page,
						fic : that.xuanList[that.xuan].id,
						keyword: that.sousuo
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							// that.list = result.data
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			pdFor(id){
				var that = this
				var idList = uni.getStorageSync('idList')?uni.getStorageSync('idList'):[];
				for(var i = 0; i < idList.length; i++) {
					if(id == idList[i]){
						return true
					}
				}
				return false
			},
			huoqu(index){
				var that = this
				that.biaoshi = index
				// var pd = that.pdFor(that.list[that.biaoshi].id)
				if(that.list[that.biaoshi].need_code == 1){
					that.dhm = true
				}else{
					uni.setStorageSync('get_type_dhm',null)
					if(that.list[that.biaoshi].type == 3){
						uni.navigateTo({
							url: '/pages/common/download?id='+that.list[that.biaoshi].id+'&name='+that.name+'&image='+that.image1
						})
					}else if(that.list[that.biaoshi].type == 1){
						uni.navigateTo({
							url: '/pages/common/richtext?id='+that.list[that.biaoshi].id+'&type=2'
						})
					}else if(that.list[that.biaoshi].type == 2){
						uni.navigateTo({
							url: '/pages/common/account?id='+that.list[that.biaoshi].id
						})
					}
				}
			},
			xuanClick(index){
				var that = this
				if(that.xuan != index){
					that.xuan = index
					that.page = 1
					that.getList()
					// if(that.xuanList[index].type == 2){
					// 	window.location.href = that.xuanList[index].url
					// }else{
					// 	that.xuan = index
					// 	that.page = 1
					// 	that.getList()
					// }
				}
			}
		}
	}
</script>

<style>
	.content {}
	.richImg {
	    width: 100% !important;
	    height: auto !important;
	}
</style>
